/*******************************************
Module: zt_http.h
E-Mail: 24zhutian@gmail.com
Notices: Copyright (c) 2007-2011 ls
*******************************************/
#ifndef zt_http_h
#define zt_http_h

#ifdef __cplusplus
extern "C" {
#endif

#define ZT_MAX_HOST_LENGTH		255
#define ZT_MAX_QUERY_LENGTH		2048
#define ZT_MAX_HEADER_LENGTH	8192
#define ZT_MAX_HTTP_CONNECT		255
#define ZT_HTTP_IO_BUF_SIZ		8192

#define ZT_HTTP_SYNC_GZIP(p)	zt_strstr((p),(u_char *)"Content-Encoding: gzip")

typedef struct {
	void *obj;					/* InternetOpen */
	void *conn;					/* InternetConnect */
	void *req;					/* HttpOpenRequest */

	u_char auto_redirect;

	zt_uint_t timeout;			/* request/response timeout */
	zt_uint_t maxconn;	
	
	zt_uint_t err;				/* Error code */	
	
	zt_uint_t StatusCode;		/* response http status code */
	zt_uint_t ContentLength;	/* response header conten-length */
	
	zt_str_t *hdr;				/* response header */
	zt_str_t *response;			/* response body */

	zt_str_t *query;			/* uri query */
	zt_str_t *host;				/* uri host */
}HttpSyncRequest;

ZT_API u_char*			zt_http_sync_request_user_agent(u_char *useragent);
ZT_API HttpSyncRequest* zt_http_sync_request_new(const u_char *useragent,zt_uint_t timeout);
ZT_API zt_int_t			zt_http_sync_request_open(HttpSyncRequest *req,const u_char *method,const u_char *uri);
ZT_API zt_int_t			zt_http_sync_request_header(HttpSyncRequest *req,const u_char *str);
ZT_API zt_int_t			zt_http_sync_request_send(HttpSyncRequest *req,const u_char *data,size_t siz);
ZT_API zt_int_t			zt_http_sync_request_close(HttpSyncRequest *req);
ZT_API zt_int_t			zt_http_sync_request_free(HttpSyncRequest *req);
ZT_API size_t			zt_http_sync_request_get(HttpSyncRequest *req,u_char *uri,u_char *hdr,zt_str_t *tmp);
ZT_API size_t			zt_http_sync_request_post(HttpSyncRequest *req,u_char *uri,u_char *hdr,zt_str_t *data,zt_str_t *tmp);

ZT_API size_t			zt_http_get(HttpSyncRequest *req,u_char *uri,u_char *hdr,zt_str_t *tmp);
ZT_API size_t			zt_http_post(HttpSyncRequest *req,u_char *uri,u_char *hdr,zt_str_t *data,zt_str_t *tmp);

#ifdef __cplusplus
}
#endif /* C++ */
#endif /* zt_http_h */